package homework;

import java.util.Stack;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/15 7:03
 */
public class MyQueue {
    private Stack<Integer> stack;
    public MyQueue() {
        stack = new Stack<>();
    }

    public boolean isEmpty(){
        return stack.isEmpty();
    }

    /**
     * 定义栈顶就是队首,所以直接弹出栈顶就是出队操作
     */
    public int dequeue (){
        return  stack.pop();
    }

    public int peek(){
        return stack.peek();
    }

    public void  enqueue(int x){
        Stack<Integer> stack2 = new Stack<>();

        while (!stack.isEmpty()){
            stack2.push(stack.pop());
        }

        stack.push(x);

        while (!stack2.isEmpty()){
            stack.push(stack2.pop());
        }

    }

}

